<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import {
  Training,
  TrainingDelete,
  checkTrainingStatus,
  checkSchool,
} from "@/http/api";

export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [],
      schoolArr: [],
      statusArr: [
        { label: "全部", value: "" },
        { label: "报名中", value: "1" },
        { label: "已关闭", value: "2" },
      ],
      queryData: {
        training_content_status: "",
        training_name: "",
        training_school_name: "",
        page: 1,
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    deleteFn(row) {
      ElMessageBox.confirm("确定删除选择的培训吗?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        TrainingDelete({ training_content_id: row.training_content_id }).then(
          (res) => {
            if (res.data.code == 1) {
              ElMessage({
                type: "success",
                message: "删除成功",
              });
              this.getData();
            }
          }
        );
      });
    },
    checkFn(row, type) {
      let str = type == 1 ? "开启" : "关闭";
      ElMessageBox.confirm(`确定${str}选择的培训吗?`, "操作提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let data = {
          training_content_id: row.training_content_id,
          status: type,
        };
        checkTrainingStatus(data).then((res) => {
          if (res.data.code == 1) {
            ElMessage({
              type: "success",
              message: "操作成功",
            });
            this.getData();
          }
        });
      });
    },
    addFn(id) {
      this.$router.push({ path: "/workListAdd", query: { id: id } });
    },
    detailFn(id) {
      this.$router.push({ path: "/workListDetail", query: { id: id } });
    },
    getData() {
      Training(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
    getSchool() {
      checkSchool().then((res) => {
        if (res.data.code == 1) {
          this.schoolArr = res.data.data;
        }
      });
    },
  },
  mounted() {},
  created() {
    this.getData();
    this.getSchool();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>培训列表(33)</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft">
          <btn value="新增" @ok="addFn"></btn>
        </div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.training_name"
                placeholder="请输入项目名称"
              />
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.training_school_name"
                filterable
                clearable
                @change="getData"
                placeholder="请输入培训学校"
              >
                <el-option
                  v-for="item in schoolArr"
                  :key="item.school_id"
                  :label="item.school_name"
                  :value="item.school_name"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.training_content_status"
                clearable
                @change="getData"
                placeholder="请选择状态"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="training_school_name"
          width="180"
          show-overflow-tooltip
          label="培训学校"
        />
        <el-table-column
          width="150"
          prop="training_name"
          show-overflow-tooltip
          label="项目名称"
        />
        <el-table-column
          prop="training_type"
          show-overflow-tooltip
          label="培训类别"
        />
        <el-table-column show-overflow-tooltip label="定金">
          <template #default="{ row }">{{ row.bm_money }}元</template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="培训价格">
          <template #default="{ row }">{{ row.bm_total_money }}元</template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="培训人数">
          <template #default="{ row }">{{ row.training_people }}人</template>
        </el-table-column>
        <el-table-column
          prop="report_time"
          width="110"
          show-overflow-tooltip
          label="报道时间"
        />
        <el-table-column
          prop="training_time"
          show-overflow-tooltip
          label="培训时长"
        />
        <el-table-column width="120" show-overflow-tooltip label="状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag v-if="row.training_content_status == 1">报名中</el-tag>
              <el-tag type="info" v-if="row.training_content_status == 2"
                >已关闭</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="Name" width="140" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="greenText ctrlText"
                @click="detailFn(row.training_content_id)"
              >
                详情
              </div>
              <div
                class="blueText ctrlText"
                @click="addFn(row.training_content_id)"
              >
                编辑
              </div>
              <div
                class="blueText ctrlText"
                @click="checkFn(row, 1)"
                v-if="row.training_content_status == 2"
              >
                开启
              </div>
              <div
                class="redText ctrlText"
                @click="checkFn(row, 2)"
                v-if="row.training_content_status == 1"
              >
                关闭
              </div>
              <div class="redText ctrlText" v-if="false" @click="deleteFn(row)">
                删除
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
